import 'package:flutter/material.dart';
import 'package:laoba_menu/views/mine/about/About.dart';
import 'package:laoba_menu/views/mine/setting/Setting.dart';
import 'package:laoba_menu/views/mine/account/Account.dart';

class FooterItem extends StatefulWidget {
  FooterItem({Key key, this.name}) : super(key: key);
  final String name;

  @override
  _FooterItemState createState() => new _FooterItemState(this.name);
}

class _FooterItemState extends State<FooterItem> {
  String name;
  _FooterItemState(this.name);
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        child: Container(
          height: 60,
          padding: const EdgeInsets.fromLTRB(20, 0, 20, 0),
          decoration: BoxDecoration(
              color: Colors.white38,
              boxShadow: [
                BoxShadow(
                    color: Colors.white,
                    offset: Offset(0.0, 0), //阴影xy轴偏移量
                    blurRadius: 1.0, //阴影模糊程度
                    spreadRadius: 1.0 //阴影扩散程度
                    )
              ],
              border: Border(
                  bottom: BorderSide(
                      width: this.name == "查看更新" ? 0.5 : 1,
                      color: Colors.black12))),
          child: Flex(
            direction: Axis.horizontal,
            children: [
              Expanded(
                child: Text(this.name),
                flex: 1,
              ),
              Expanded(
                child: Icon(
                  Icons.chevron_right,
                  color: Colors.black,
                ),
                flex: 0,
              )
            ],
          ),
        ),
        onTap: () => updateText(this.name));
  }

  // 选项点击
  void updateText(String s) async {
    switch (s) {
      case "设置":
        print("点击了1");
        //导航到新路由
        Navigator.push(context, MaterialPageRoute(builder: (context) {
          return Setting();
        }));
        break;
      case "收藏":
        print("点击了2");
        break;
      case "菜谱管理":
        print("菜谱管理");
        break;
      case "账户":
        print("点击了3");
        Navigator.push(context, MaterialPageRoute(builder: (context) {
          return Account();
        }));
        break;

      case "关于我们":
        print("点击了4");
        Navigator.push(context, MaterialPageRoute(builder: (context) {
          return About();
        }));
        break;
      case "查看更新":
        //弹出对话框并等待其关闭
        bool delete = await showDeleteConfirmDialog1();
        if (delete == null) {
          print("取消");
        } else {
          print("确认");
        }
        break;
      default:
    }
  }

  // 弹出对话框
  Future<bool> showDeleteConfirmDialog1() {
    return showDialog<bool>(
      context: context,
      builder: (context) {
        return AlertDialog(
          title: Text("提示"),
          content: Text("当前已是最新版本?"),
          actions: <Widget>[
            FlatButton(
              child: Text("取消"),
              onPressed: () => Navigator.of(context).pop(), // 关闭对话框
            ),
            FlatButton(
              child: Text("确认"),
              onPressed: () {
                //关闭对话框并返回true
                Navigator.of(context).pop(true);
              },
            ),
          ],
        );
      },
    );
  }
}
